package com.luguangtao.controller;

import com.luguangtao.common.utils.FileService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

/**
 * @类名: com.luguangtao.controller
 * @作者: lgt
 * @创建时间: 2019-12-07 19:10
 * @描述:
 **/
@Controller
@CrossOrigin
public class FileController {

    //上传
    @ResponseBody
    @PostMapping("fileuploads")
    public String fileuploads(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        File file1 = new File("D://pic" + File.separator + originalFilename);
        file.transferTo(file1);
        return originalFilename;
    }

    //下载
    @RequestMapping("downLoad")
    public String downLoad(HttpServletResponse response, HttpServletRequest request){
        FileService.downLoad(response,request);
        return null;
    }
}
